package ar.uba.fi.RSACryptoFiuba.view.encrypt;

import java.awt.Font;

import javax.swing.BorderFactory;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.border.TitledBorder;

import ar.uba.fi.RSACryptoFiuba.view.commons.NavigableKeyActionListener;


@SuppressWarnings("serial")
public class EncryptProgressPanel extends JPanel{
	
	private JLabel messageLabel;
    private JTextField messageValue;
    private JLabel publicKeyLabel;
    private JTextField publicKeyValue;
    private JLabel numericalRepresentationLabel;
    private JTextField numericalRepresentationValue;
	private JLabel cryptogramLabel;
    private JTextField cryptogramValue;
	
	public EncryptProgressPanel(){
		super();
		initComponentes();
	}
	
	private void initComponentes(){		
	
        this.setBorder(BorderFactory.createTitledBorder(null, "Progreso", TitledBorder.LEFT, TitledBorder.DEFAULT_POSITION));
        this.setToolTipText("");

        messageLabel = new JLabel();
        messageLabel.setFont(new Font("Ubuntu", 1, 15));
        messageLabel.setText("Mensaje:");

        messageValue = new JTextField(6);
        messageValue.setBackground(getBackground());
        messageValue.setBorder(BorderFactory.createEmptyBorder());
        messageValue.addKeyListener(new NavigableKeyActionListener());


        publicKeyLabel = new JLabel();;
        publicKeyLabel.setFont(new Font("Ubuntu", 1, 15));
        publicKeyLabel.setText("Clave Pública:");
        
        publicKeyValue = new JTextField(6);
        publicKeyValue.setBackground(getBackground());
        publicKeyValue.setBorder(BorderFactory.createEmptyBorder());
        publicKeyValue.addKeyListener(new NavigableKeyActionListener());

        numericalRepresentationLabel = new JLabel();
        numericalRepresentationLabel.setFont(new Font("Ubuntu", 1, 15));
        numericalRepresentationLabel.setText("Rep Numérica:");

        numericalRepresentationValue = new JTextField(6);
        numericalRepresentationValue.setBackground(getBackground());
        numericalRepresentationValue.setBorder(BorderFactory.createEmptyBorder());
        numericalRepresentationValue.addKeyListener(new NavigableKeyActionListener());

        cryptogramLabel = new JLabel();
        cryptogramLabel.setFont(new Font("Ubuntu", 1, 15));
        cryptogramLabel.setText("Criptograma:");

        cryptogramValue = new JTextField(6);
        cryptogramValue.setBackground(getBackground());
        cryptogramValue.setBorder(BorderFactory.createEmptyBorder());
        cryptogramValue.addKeyListener(new NavigableKeyActionListener());
        
        GroupLayout encryptProgressPanelLayout = new GroupLayout(this);
        this.setLayout(encryptProgressPanelLayout);
        encryptProgressPanelLayout.setHorizontalGroup(
            encryptProgressPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(encryptProgressPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(encryptProgressPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                    .addComponent(messageLabel)
                    .addComponent(publicKeyLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(encryptProgressPanelLayout.createParallelGroup(GroupLayout.Alignment.LEADING)
                    .addComponent(messageValue, GroupLayout.PREFERRED_SIZE, 137, GroupLayout.PREFERRED_SIZE)
                    .addComponent(publicKeyValue, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(ComponentPlacement.UNRELATED)
                .addGroup(encryptProgressPanelLayout.createParallelGroup(Alignment.LEADING, false)
                    .addComponent(numericalRepresentationLabel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(cryptogramLabel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(encryptProgressPanelLayout.createParallelGroup(Alignment.LEADING, false)
                    .addComponent(numericalRepresentationValue, GroupLayout.DEFAULT_SIZE, 260, Short.MAX_VALUE)
                    .addComponent(cryptogramValue, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        encryptProgressPanelLayout.setVerticalGroup(
            encryptProgressPanelLayout.createParallelGroup(Alignment.LEADING)
            .addGroup(encryptProgressPanelLayout.createSequentialGroup()
                .addGroup(encryptProgressPanelLayout.createParallelGroup(Alignment.BASELINE)
                    .addComponent(messageLabel)
                    .addComponent(messageValue)
                    .addComponent(numericalRepresentationLabel)
                    .addComponent(numericalRepresentationValue))
                .addPreferredGap(ComponentPlacement.UNRELATED)
                .addGroup(encryptProgressPanelLayout.createParallelGroup(Alignment.BASELINE)
                    .addComponent(publicKeyLabel)
                    .addComponent(publicKeyValue)
                    .addComponent(cryptogramLabel)
                    .addComponent(cryptogramValue))
                .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
	}

	public String getMessageValue() {
		return messageValue.getText();
	}

	public void setMessageValue(String messageValue) {
		this.messageValue.setText(messageValue);
	}

	public String getPublicKeyValue() {
		return publicKeyValue.getText();
	}

	public void setPublicKeyValue(String publicKeyValue) {
		this.publicKeyValue.setText(publicKeyValue);
	}

	public String getNumericalRepresentationValue() {
		return numericalRepresentationValue.getText();
	}

	public void setNumericalRepresentationValue(String numericalRepresentationValue) {
		this.numericalRepresentationValue.setText(numericalRepresentationValue); 
	}

	public String getCryptogramValue() {
		return cryptogramValue.getText();
	}

	public void setCryptogramValue(String cryptogramValue) {
		this.cryptogramValue.setText(cryptogramValue);
	}
	
	public void setNumericalRepresentationCaretPosition(int position){
		this.numericalRepresentationValue.setCaretPosition(position/2);
	}
}